﻿@model IEnumerable<GZNest.Entity.Spin.System.Machine>

@{
    ViewBag.Title = "Machine List";
}

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<div class="row">
    <div class="col-md-6">
        <div class="panel panel-default ">
            <div class="panel-heading">
                Machine Overview
            </div>
            <table class="table table-striped table-bordered table-hover">
                <tr>
                    <th>
                        @Html.DisplayNameFor(model => model.Name)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Description)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Enabled)
                    </th>
                    <th></th>
                </tr>

                @foreach (var item in Model)
            {
                    <tr>
                        <td>
                            @Html.DisplayFor(modelItem => item.Name)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.Description)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.Enabled)
                        </td>
                        <td>
                            @Html.ActionLink("Edit", "Edit", new { id = item.Id }, new { @class = "btn btn-primary btn-sm" }) |
                            @*@Html.ActionLink("Details", "Details", new { id=item.Id }) |*@
                            @Html.ActionLink("Delete", "Delete", new { id = item.Id },
           new { @class = "btn btn-danger btn-sm", onclick = "return confirm('are you sure you wish to delete this machine?')" })
                        </td>
                    </tr>
                }

            </table>
        </div>
    </div>
</div>

@*<table class="table">
        <thead>
            <tr><th>name</th><th>description</th><th>Enabled</th><th></th></tr>
        </thead>
        <tbody data-bind="foreach: machines">
            <tr>
                <td data-bind="text: Name"></td>
                <td data-bind="text: Description"></td>
                <td data-bind="text: Enabled"></td>
                <td>
                    <button data-bind="click: $root.edit">Edit</button>
                    <button data-bind="click: $root.delete">Delete</button>
                </td>
            </tr>
        </tbody>
    </table>*@


@section scripts{
    @*@Scripts.Render("~/Areas/Spin/Scripts/ViewModels/MachineListVM.js")*@
    @*<script type="text/javascript" src="~/Areas/Spin/Scripts/ViewModels/MachineListVM.js"></script>*@
    @*<script type="text/javascript">
            var MachineListVM = function () {
                var self = this;
                self.machines = ko.observableArray([]);

                $.getJSON(
                   "/Spin/Machine/List",
                   function (data, textStatus) {
                       if (textStatus == 'success') {
                           var array = [];
                           $.each(data, function (index, value) {
                               array.push(value);
                           });
                           self.machines(array);
                       }
                       else {
                           alert(textStatus);
                       }
                   });
            }

            ko.applyBindings(new MachineListVM());
        </script>*@
}
